import java.io.*;

public class Main3 {
    //（3）使用字符输入输出流将这10个对象存入文本文件（每行一本书）中并读出到一List集合中。
    public static void main(String[] args) throws IOException {
        Book[] books=new Book[10];
        books[0]=new Book(1,"a","z");
        books[1]=new Book(2,"b","q");
        books[2]=new Book(3,"c","s");
        books[3]=new Book(4,"d","l");
        books[4]=new Book(5,"e","z");
        books[5]=new Book(6,"f","w");
        books[6]=new Book(7,"g","z");
        books[7]=new Book(8,"h","w");
        books[8]=new Book(9,"i","y");
        books[9]=new Book(10,"j","l");
        ObjectOutputStream outputStream = new ObjectOutputStream(new FileOutputStream("d:/test3.txt"));
        for (int i = 0; i <books.length ; i++) {
            outputStream.writeObject(books[i]);//写入
        }
        ObjectInputStream objectInputStream=new ObjectInputStream(new FileInputStream("d:/test3.txt"));

            while (true) {
                try {
                    Book book = (Book) objectInputStream.readObject();
                    System.out.println(book);
                } catch (ClassNotFoundException e) {
                    throw new RuntimeException(e);
                }
            }
    }
}
